#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <PowerupsX>

#define PREFIX "{olive}PowerupsX {default}>{green} "

new AbilityGravity;

public Plugin:myinfo= 
{
	name="PowerupsXL Gravity",
	author="Skydive",
	description="Powerups X Gravity Ability",
	version="1.0",
	url=""
};

public OnPluginStart()
{
	NativeIncStart();
	
	AbilityGravity = PX_RegisterAbility("AbilityGravity");
	PX_SetAbilityName(AbilityGravity,"Low Gravity");
	PX_SetAbilityDescription(AbilityGravity,"Gravity: 1.0-Level/10");
	PX_SetAbilityUsage(AbilityGravity,"Jump Higher, Land Slower!");
	PX_AbilityUseColor(AbilityGravity,true);
	PX_SetAbilityColor(AbilityGravity,155,255,155,255);
	PX_SetAbilityMaxLevel(AbilityGravity,6);
	
	HookEvent("player_spawn",Event_PlayerSpawn);
}

public PXF_OnAbilityGiven(Client, Ability)
{	
	if(Ability == AbilityGravity)
	{	
		new Level = PX_GetLevel(Client, Ability);
		new Float:fGravity = 1.0-float(Level/10);
		SetEntityGravity(Client,fGravity);
	}
}

public Action:Event_PlayerSpawn(Handle:event, const String:name[],bool:dontBroadcast)
{
	new userid = GetClientOfUserId(GetEventInt(event,"userid"));
	if(PX_GetAbility(userid) == AbilityGravity)
	{
		new Level = PX_GetLevel(userid, PX_GetAbility(userid));
		new Float:fGravity = 1.0-float(Level/10);
		SetEntityGravity(userid,fGravity);
	}
}

public PXF_OnAbilityRemoved(Client, Ability)
{
	if(Ability == AbilityGravity)
	{
		SetEntityGravity(Client,1.0);
	}
}

public PXF_OnLevelChanged(Client, Ability, NewLevel)
{
	if(Ability == AbilityGravity)
	{
		new Float:fGravity = 1.0-float(NewLevel/10);
		SetEntityGravity(Client,fGravity);
	}
}